﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Windows.Forms;

namespace TNCAddIn
{
    class Password
    {
        //要求输入密码
        public void Show() 
        {
            PasswdForm pf = new PasswdForm();
            pf.ShowDialog();
            if (pf.DialogResult == DialogResult.OK)
            {
                //使用MD5对密码进行加密，保存
                MD5 m = new MD5CryptoServiceProvider();
                byte[] s = m.ComputeHash(UTF8Encoding.UTF8.GetBytes(pf.Key));
                Properties.Settings.Default.Key = "";
                for (int i = 0; i < s.Length; i++)
                {
                    Properties.Settings.Default.Key += s[i].ToString("x2");
                }

                Properties.Settings.Default.ServerBaseUrl = pf.TnrUrl;

                Properties.Settings.Default.Save();
            }
        }
    }
}